package org.jeecg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.domain.ServeItem;
import org.jeecg.domain.ServeType;
import org.jeecg.domain.dto.FindDto;
import org.jeecg.service.ServeItemService;
import org.jeecg.mapper.ServeItemMapper;
import org.jeecg.service.ServeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.jeecg.util.ResponseResult;

/**
* @author ASUS
* @description 针对表【serve_item(服务项表)】的数据库操作Service实现
* @createDate 2024-12-21 09:02:37
*/
@Service
public class ServeItemServiceImpl extends ServiceImpl<ServeItemMapper, ServeItem>
    implements ServeItemService{
    @Autowired
    private ServeTypeService typeService;
    @Override
    public ResponseResult findAll(FindDto findDto) {
        Page<ServeItem> page=new Page<>(findDto.getPageNum(),findDto.getPageSize());
        LambdaQueryWrapper<ServeItem> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(findDto.getName()),ServeItem::getName,findDto.getName())
                .eq(StringUtils.isNotBlank(findDto.getServeTypeId()),ServeItem::getServeTypeId,findDto.getServeTypeId())
                .eq(findDto.getActiveStatus()!=null,ServeItem::getActiveStatus,findDto.getActiveStatus());
        Page<ServeItem> page1 = this.page(page, wrapper);
        for (ServeItem record : page1.getRecords()) {
            ServeType byId = typeService.getById(record.getServeTypeId());
            if(byId!=null){
                record.setItemType(byId);
            }
        }
        return ResponseResult.okResult(page1);
    }

    @Override
    public ResponseResult qi(String id) {
        ServeItem byId = this.getById(id);
        byId.setActiveStatus(2);
        this.updateById(byId);
        return ResponseResult.okResult(byId);
    }

    @Override
    public ResponseResult jin(String id) {
        ServeItem byId = this.getById(id);
        byId.setActiveStatus(1);
        this.updateById(byId);
        return ResponseResult.okResult(byId);
    }

    @Override
    public ResponseResult deleteItem(String id) {
        this.removeById(id);
        return ResponseResult.okResult(200);
    }

}




